long long superMod(int x, int y, int n)
{
    if (x == 0)
        return 0;
    if (y == 0)
        return x % n;
    if (y == 1)
        return (x * 10) % n;
    if (y % 2 == 0)
    {
        return (superMod(x, y / 2, n) * superMod(1, y / 2, n)) % n;
    }
    else
    {
        return (superMod(x, y / 2, n) * superMod(1, y / 2 + 1, n)) % n;
    }
}
int solve(string a, string b, int n)
{
    long result = 0;
    for (int i = 0; i < a.length(); i++)
    {
        int x = a[i] - '0';
        int temp = superMod(x, a.length() - i - 1, n);
        result = (result + temp) % n;
    }
    for (int i = 0; i < b.length(); i++)
    {
        int x = b[i] - '0';
        int temp = superMod(x, b.length() - i - 1, n);
        result = (result + temp) % n;
    }
    return result;
}